import { defineConfig } from 'wxt'
import UnoCSS from 'unocss/vite'
import { presetWind3, presetAttributify, presetIcons } from 'unocss'
import dayjs from 'dayjs'
const isDev = process.env.NODE_ENV === 'development'
// See https://wxt.dev/api/config.html
export default defineConfig({
  srcDir: 'src',
  outDir: 'dist',
  runner: {
    openConsole: true,
    openDevtools: true,
    disabled: true,
  },
  modules: ['@wxt-dev/module-vue'],
  vite: () => ({
    plugins: [
      UnoCSS({
        presets: [presetWind3(), presetAttributify(), presetIcons()],
      }),
    ],
  }),
  manifest: ({ mode }) => {
    const modeStr = mode === 'development' ? ' (开发)' : '(线上)'
    const datetime = dayjs().format('YYYY-MM-DD HH:mm')
    return {
      manifest_version: 3,
      name: `AI采购助手 ${datetime}` + modeStr,
      version: '1.1',
      description: 'AI采购助手' + modeStr,
      permissions: ['storage', 'tabs', 'sidePanel', 'scripting', 'activeTab', 'commands', 'action', 'downloads'],
      action: {},
      host_permissions: [
        'https://*.1688.com/*',
        'http://*.cjdropshipping.offline.pre.cn/*',
        'https://*.cjdropshipping.offline.pre.cn/*',
        'https://*.cjdropshipping.cn/*',
      ],
      background: {
        service_worker: 'background.js',
        type: 'module',
        persistent: true,
      },
      content_scripts: [
        {
          matches: ['https://detail.1688.com/*'],
          js: ['content-script.js'],
        },
      ],
      side_panel: {
        default_path: 'sidepanel.html',
        persistent: true,
      },
      commands: {
        toggle_sidepanel: {
          // 使用更具体的命令名称
          suggested_key: {
            windows: 'Ctrl+Shift+L',
            mac: 'Command+Shift+L',
            chromeos: 'Ctrl+Shift+L',
            linux: 'Ctrl+Shift+L',
          },
          description: '打开/关闭侧边栏', // 添加命令描述
        },
      },
    }
  },
  zip: {
    name: `AI采购助手 ${dayjs().format('YYYY-MM-DD HH:mm')} (${isDev ? '开发' : '线上'})`,
  },
})
